package com.ziyun.admin.web.config.shiro;

import org.apache.shiro.cache.Cache;
import org.apache.shiro.cache.CacheException;
import org.apache.shiro.cache.CacheManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

/**
 * redis CacheManager 实现shiro CacheManager
 * @author zh
 * @date 2018/8/1110:52
 */
@Service
public class RedisCacheManager implements CacheManager {

    //@Qualifier("zyRedisTemplate")
    @Autowired
    private RedisTemplate redisTemplate;

   /* @Override
    public <K, V> Cache<K, V> getCache(String name) throws CacheException {
        return new RedisCache<K, V>(name, redisTemplate);// 为了简化代码的编写，此处直接new一个Cache
    }*/

    public <K, V> Cache<K, V> getCache(String name) throws CacheException {
        return new ShiroCache<K, V>(name, redisTemplate);
    }
}
